package com.leo;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.DepthTest;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Box;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;

/**
 * @ClassName CameraDemo
 * @Description 相机
 * @Author wangss
 * @date 2020.07.05 18:06
 * @Version 1.0
 */
public class CameraDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();

        HBox hBox = new HBox(100);
        hBox.setAlignment(Pos.CENTER);

        Box box1 = new Box(150, 150, 150);
        Box box2 = new Box(150, 150, 150);
        Box box3 = new Box(150, 150, 150);

        hBox.getChildren().addAll(box1, box2, box3);

        an.setStyle("-fx-background-color: #FFFFFF00");
        an.getChildren().addAll(hBox);
        an.setDepthTest(DepthTest.ENABLE);
        AnchorPane.setTopAnchor(hBox, 100d);
        AnchorPane.setLeftAnchor(hBox, 100d);

        Scene scene = new Scene(an, 1200, 800, true, SceneAntialiasing.BALANCED);

        PerspectiveCamera camera = new PerspectiveCamera();
        camera.setRotationAxis(Rotate.Y_AXIS);
        camera.setRotate(60);

        // 视野范围
        camera.setFieldOfView(100);

        // 近景裁切
        camera.setNearClip(1.2);

        scene.setCamera(camera);

        primaryStage.setScene(scene);
        primaryStage.setTitle("3D介绍");
        primaryStage.setWidth(1200);
        primaryStage.setHeight(800);
        primaryStage.show();
    }
}
